﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RTW.Core.Repository;

namespace RTW.Servers
{
   public class BaseServers<T> where T : class, new()
    {
        private readonly IRepositoryAsync<T> _Repository;
        public BaseServers()
        {
            _Repository = new DapperAsyncRepository<T>();
        }

        //查询
        public async Task<List<T>> GetAll() {
            return (await _Repository.GetAllEnumerableAsync()).ToList();
        }

        public async Task<T> GetById(object id) {
            return await _Repository.GetByIdAsync(id);
        }

        public async Task<bool> Any(object id)
        {
            return (await _Repository.GetByIdAsync(id)).Equals(0);
        }

        public async Task<int> Count()
        {
            return await _Repository.Count();
        }

        public async Task<int> Add(T model)
        {
            return await _Repository.InsertAsync(model);
        }


        public async Task<int> Edit(T model)
        {
            return await _Repository.UpdateAsync(model);
        }

        public async Task<int> Del(T model)
        {
            return await _Repository.DeleteAsync(model);
        }

        public async Task<int> Del(string ids)
        {
            return await _Repository.DeleteByIdsAsync(ids);
        }


    }
}
